<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Models\Admin\TvipCostOrder;

class UserController extends CommonController {

	/**
	 * 后台登录页面
	 * @param Request $request
	 * @return mixed
	 */
	public function login(Request $request){
		if($request->isMethod('post')){
			$username = $request->input('username');
			$password = $request->input('password');
			// if(!in_array($username,$this->mobile)){
			// 	$this->ajax_error('您没有授权登录操作');
			// }
			$userInfo = DB::table('tnet_reginfo')->where(array('nodecode' => $username))->first();
			if(!$userInfo){
				$this->ajax_error('用户名不存在');
			}

			$md5_password = $this->gen_password($userInfo->nodeid,$password);

			if($md5_password != $userInfo->userpwd){
				$this->ajax_error('密码不正确');
			}else{
				$_SESSION['admin_uid'] = $userInfo->nodeid;
				$this->ajax_success('登录成功');
			}
		}
		return view('admin.user.login');
	}

	/**
	 * 后台账号退出页面
	 */
	public function logout(){
		header('Content-Type: text/html; charset=utf-8');
		unset($_SESSION['admin_uid']);
		session_destroy();
		header( "Location:".asset('user/login'));
	}
	/**
	 * @param $mobile 商家手机号
	 * 商家后台登录密码加密规则：strtolower(md5(密码.'shop__'))
	 */
	protected function merchant_pwd($mobile){
		return strtolower(md5($mobile.'shop__'));
	}
}